home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / zmdm / main.c < prev    next >
C/C++ Source or Header  |  1993-06-26  |  10KB  |  492 lines

  1. /*
  2.  *     Main Module
  3.  *
  4.  *        Jwahar Bammi
  5.  *            usenet: cwruecmp!bammi@decvax.UUCP
  6.  *            csnet:  bammi@cwru.edu
  7.  *            arpa:   bammi@cwru.edu
  8.  *            CompuServe: 71515,155
  9.  */
  10.  
  11.  
  12. #include "zmdm.h"
  13.  
  14. #ifndef Vsync             /* Atari forgot these in osbind.h */
  15. #define Vsync()    xbios(37)
  16. #endif
  17.  
  18. #define    esc    27
  19. #define cr    0x0d
  20. #define mvto(r,c)    EscSeq('Y');Bconout(2,r+040);Bconout(2,c+040)
  21.  
  22.      /* Global variable  definitions, extern everywhere else */
  23. int *aline_addr;        /* Base addr of aline variables */
  24. int hlines = 25;        /* # of lines on screen        */
  25. int rez;            /* current resolution        */
  26. int scolor = 0;            /* current fg/bg screen color toggle */
  27. long *ms_ptr;            /* Pointer to my screen memory, aligned at
  28.                    a 256 bytes boundary */
  29.  
  30. #ifndef MWC
  31. long m_screen[8*1024+32];    /* My screen memory
  32.                    32K bytes + 256 Bytes guard for alignement
  33.                    In the worst case when we align we have to
  34.                    go 255 bytes from &m_screen[0], hence the
  35.                    256 Byte guard is required */
  36. #else
  37. #ifdef RECURSE
  38. #ifdef BIGSTACK
  39. long _stksize = 128L * 1024L;
  40. #else
  41. long _stksize = 16L * 1024L;
  42. #endif
  43. #else
  44. long _stksize = 16384L;
  45. #endif /* RECURSE */
  46.  
  47. long *m_screen;            /* Presently Mark Willams will not allow
  48.                    > 32K static structures */
  49. extern unsigned char *bufr;        /* Here for the same reason */
  50. #endif /* MWC */
  51.  
  52. struct stat statbuf;          /* Disk Transfer address for Find first etc */
  53. int Baudrate;              /* Current baud rate                  */
  54. long drv_map;              /* bit vector of valid drives */
  55.     
  56.      /* Types */
  57.  
  58.  
  59.      /* Globals belonging to this module only */
  60. IOREC save,    /* the original Iorec is saved here for the duration of this
  61.            process */
  62.      *p;    /* ptr returned by Iorec() */
  63.  
  64. char iobuf[IBUFSIZ]; /* My large Rs232 receive buffer */
  65.  
  66. int    rs232 = 1,        /* Ports */
  67.         console = 2;
  68. int    speed,              /* rs232 setup parameters */
  69. #ifdef FLOW_CTRL
  70.      flowctl = 1,
  71. #else
  72.     flowctl = 0,
  73. #endif
  74.     ucr = -1,
  75.     rsr = -1,
  76.     tsr = -1,
  77.     scr = -1;
  78.  
  79. /*
  80.  * SetIoBuf() - Save the systems Rs232 buffer and install my large
  81.  * Rs232 buffer.
  82.  *
  83.  */
  84. void SetIoBuf()
  85. {
  86.     /* Get pointer to Rs232 input record */
  87.     p = (IOREC *)Iorec(0);
  88.     
  89.     /* Save the info */
  90.     save.ibuf    = p->ibuf;
  91.     save.ibufsiz    = p->ibufsiz;
  92.     save.ibufhd    = p->ibufhd;
  93.     save.ibuftl    = p->ibuftl;
  94.     save.ibuflow    = p->ibuflow;
  95.     save.ibufhi    = p->ibufhi;
  96.     
  97.     /* Install my buffer in its place */
  98.     p->ibuf        = &iobuf[0];
  99.     p->ibufsiz    = IBUFSIZ;
  100.     p->ibuflow    = IBUFSIZ/4;
  101.     p->ibufhi    = IBUFSIZ / 4 * 3;
  102.     p->ibufhd = p->ibuftl = 0;
  103.     
  104. }
  105.  
  106. /*
  107.  * ResetIoBuf() - Reset the Rs232 buffer to the saved (system's) buffer
  108.  *
  109.  */
  110. void ResetIoBuf()
  111. {
  112.     p->ibuf        = save.ibuf;
  113.     p->ibufsiz    = save.ibufsiz;
  114.     p->ibuflow    = save.ibuflow;
  115.     p->ibufhi    = save.ibufhi;
  116.     p->ibufhd    = save.ibufhd;
  117.     p->ibuftl    = save.ibuftl;
  118. }
  119.  
  120.  
  121. /*
  122.  * setRs232() - set rs232 port configuration
  123.  */
  124. void setRs232 ()
  125. {
  126.     char ch;
  127.     long conin;
  128.     
  129.     Bconws("Baud rate: ");
  130.     EscSeq('p');
  131.     Bconws("0=19200 1=9600, 2=4800, 3=2400, 4=1200, 5=300\r\n");
  132.     EscSeq('q');
  133.     Bconout(2, '\t');
  134.     EscSeq('p');
  135.     Bconws("What speed==>");
  136.     EscSeq('q');
  137.     
  138.     conin = Bconin(console);    /* get speed */
  139.     if ((conin & 0x00FF0000L) == 0x00610000L)
  140.     {
  141.         his_screen();
  142.         ResetIoBuf();
  143.         finish();
  144.     }
  145.     ch = (char) (conin & 0x007f);
  146.     Bconout(2, ' ');
  147.     switch (ch)
  148.     {
  149.         case '0':        /* 19200 */
  150.         speed = 0;
  151.         Bconws("19200");
  152.         Baudrate = 19200;
  153.         break;
  154.         
  155.         case '1':
  156.         speed = 1;    /* 9600 */
  157.         Bconws("9600");
  158.         Baudrate = 9600;
  159.         break;
  160.         
  161.         case '2':
  162.         speed = 2;    /* 4800 */
  163.         Bconws("4800");
  164.         Baudrate = 4800;
  165.         break;
  166.         
  167.         case '3':
  168.         speed = 4;    /* 2400 */
  169.         Bconws("2400");
  170.         Baudrate = 2400;
  171.         break;
  172.         
  173.         case '4':
  174.         speed = 7;    /* 1200 */
  175.         Bconws("1200");
  176.         Baudrate = 1200;
  177.         break;
  178.         
  179.         case '5':
  180.         speed = 9;    /* 300 */
  181.         Bconws("300");
  182.         Baudrate = 300;
  183.         break;
  184.         
  185.         default:
  186.         speed = BAUD_DEFAULT;
  187.         Bconws(BAUD_STRING);
  188.         Baudrate = BAUD_RATE;
  189.     }
  190.     Bconws(" Baud\r\n");
  191.     
  192.     /* Set new Baud rate */
  193.  
  194. /*    Txoff(); */
  195.     Rsconf(speed, flowctl, ucr, rsr, tsr, scr);
  196.     Vsync(); Vsync();
  197. /*    Txon(); */
  198.  
  199.     
  200. }
  201.  
  202. /*
  203.  * help() - display help info and menu
  204.  */
  205. void help ()
  206. {
  207.     register long conin;
  208.     extern char *r_filename();
  209.     
  210.     my_screen();        /* Switch to my screen memory */
  211.     EscSeq('v');        /* wrap at end of line */
  212.     EscSeq('E');        /* clear screen */
  213.     
  214.     mvto(2,32);
  215.     EscSeq('p');
  216.     Bconws("ZMDM Version ");
  217.     Bconws(ZMDMVERSION);
  218.     EscSeq('q');
  219.     mvto(4,29);
  220.     Bconws("ST Enthusiasts @ CWRU\r\n\n");
  221.  
  222.     /* Put up menu */
  223.     Bconws("\r\n\t");
  224.     EscSeq('p');        /* reverse video */
  225.     Bconws("Undo");
  226.     EscSeq('q');        /* quit reverse video */
  227.     Bconws(" to exit.\r\n");
  228.     
  229.     Bconws("\t");
  230.     EscSeq('p');        /* reverse video */
  231.     Bconws("Help");
  232.     EscSeq('q');        /* quit reverse video */
  233.     Bconws(" for this message.\r\n");
  234.  
  235.     Bconws("\t");
  236.     EscSeq('p');        /* reverse video */
  237.     Bconws("Escape");
  238.     EscSeq('q');        /* quit reverse video */
  239.     Bconws(" to send a break.\r\n");
  240.     
  241.     Bconws("\t");
  242.     EscSeq('p');        /* reverse video */
  243.     Bconws("T or t");
  244.     EscSeq('q');        /* quit reverse video */
  245.     Bconws(" to do file transfers and local functions.\r\n");
  246.  
  247.     if(rez == 2)
  248.     {
  249.         Bconws("\t");
  250.         EscSeq('p');        /* reverse video */
  251.         Bconws("H or h");
  252.         EscSeq('q');        /* quit reverse video */
  253.         Bconws(" for Hi Rez Toggle (25/50 Lines).\r\n");
  254.     }
  255.  
  256.     Bconws("\t");
  257.     EscSeq('p');        /* reverse video */
  258.     Bconws("I or i");
  259.     EscSeq('q');        /* quit reverse video */
  260.     Bconws(" to Invert screen colors.\r\n");
  261.     
  262.     Bconws("\t");
  263.     EscSeq('p');        /* reverse video */
  264.     Bconws("Return");
  265.     EscSeq('q');        /* quit reverse video */
  266.     Bconws(" to do nothing.\r\n");
  267.     
  268.     Bconws("\t");
  269.     EscSeq('p');        /* reverse video */
  270.     Bconws("B or b");
  271.     EscSeq('q');        /* quit reverse video */
  272.     Bconws(" to set baud rate.     Default is ");
  273.     EscSeq('p');
  274.     Bconws(BAUD_STRING);
  275.     Bconws(" Baud.\r\n\r\n");
  276.     EscSeq('q');
  277.  
  278.     /* get response */
  279.     conin = Bconin(console);
  280.  
  281.     if ((conin & 0x00FF0000L) == 0x00610000L)
  282.     {
  283.         /* He hit <UNDO> */
  284.         his_screen();
  285.         ResetIoBuf();
  286.         finish();
  287.     }
  288.     
  289.     switch((int)(conin & 0x007f))
  290.     {
  291.         case 'B':
  292.         case 'b':
  293.         /* Set baud rate */
  294.         setRs232();
  295.         break;
  296.         
  297.         case 'T':
  298.         case 't':
  299.             EscSeq('E');        /* clear screen */
  300.  
  301.             /* Set no flow Control */
  302. #ifdef FLOW_CTRL
  303.             Rsconf(-1,0,-1,-1,-1,-1);
  304.             Vsync(); Vsync();
  305.  
  306. #endif
  307.         /* Go do transfers */
  308.         transfer();
  309.             
  310. #ifdef FLOW_CTRL
  311.             /* Flow Control On */
  312. /*            Txoff(); */
  313.             Rsconf(-1,1,-1,-1,-1,-1);
  314.             Vsync(); Vsync();
  315. /*            Txon(); */
  316. #endif
  317.         his_screen();
  318.         return;
  319.         
  320.         case '\033':
  321.         /* Send a break */
  322.         sendbrk();
  323.         his_screen();    /* Don't wait for the key hit */
  324.  
  325.         return;
  326.  
  327.         case 'i':
  328.         case 'I':
  329.         /* Invert screen colors */
  330.         his_screen();
  331.         if(scolor == 0)
  332.         {
  333.             EscSeq('b');    /* Foreground color 0 */
  334.             Bconout(2, 0);
  335.             EscSeq('c');    /* Background color 1 */
  336.             Bconout(2, 1);
  337.             scolor = 1;
  338.         }
  339.         else
  340.         {
  341.             EscSeq('b');    /* Foreground color 1 */
  342.             Bconout(2, 1);
  343.             EscSeq('c');    /* Background color 0 */
  344.             Bconout(2, 0);
  345.             scolor = 0;
  346.         }
  347.         EscSeq('E');        /* Clear the screen */
  348.         return;
  349.  
  350.         case 'h':
  351.         case 'H':
  352.         /* Hi rez 25/50 toggle */
  353.         if(rez == 2)
  354.         {
  355.             if(hlines == 25)
  356.             {
  357.                 hlines = 50;
  358.                 hi50();
  359.             }
  360.             else
  361.             {
  362.                 hlines = 25;
  363.                 hi25();
  364.             }
  365.             his_screen();
  366.             EscSeq('E');        /* clear screen */
  367.             return;
  368.         }
  369.         /* else fall Through */
  370.         
  371.         default:
  372.         Bconws("No Change\r\n");
  373.     }
  374.  
  375.     /* Wait for a key hit */
  376.     hit_key();
  377.     /* back to terminal screen */
  378.     his_screen();
  379. }
  380.  
  381. main ()
  382. {
  383.     register int    c;        /* rs232 input */
  384.     register int    i;
  385.     register long    conin;
  386.     extern int *aaddress(); /* Routine that returns base address of
  387.                  * line A variables
  388.                  */
  389. #ifdef MWC
  390.     extern char *lmalloc();
  391. #endif
  392.  
  393.     /* Set up Dta */
  394.     Fsetdta(&statbuf);
  395.  
  396.     /* Get screen rez */
  397.     rez = Getrez();
  398.     drv_map = Drvmap();
  399.  
  400. #ifdef MWC
  401.        if((m_screen = (long *)lmalloc(
  402.                    (unsigned long)((8L*1024L+32L)*(long)sizeof(long))))
  403.                             == (long *)NULL)
  404.     {
  405.         Bconws("Sorry, could not allocate enough memory\r\n");
  406.         Pterm(3);
  407.     }
  408.     if((bufr = (unsigned char *)lmalloc((unsigned long)BBUFSIZ))
  409.                      == (unsigned char *)NULL)
  410.     {
  411.         Bconws("Sorry, could not allocate enough memory\r\n");
  412.         Pterm(4);
  413.     }
  414.  
  415. #endif /* MWC */
  416.  
  417. #ifdef MWC
  418.     ms_ptr = (long *) ((0xffffff00L & ((long)(m_screen))) + 0x00000100L);
  419. #else
  420.     ms_ptr = (long *) ((0xffffff00L & ((long)(&m_screen[0]))) + 0x00000100L);
  421. #endif /* MWC */
  422.  
  423.     EscSeq('e');        /* Turn on the cursor */
  424.     EscSeq('v');        /* wrap at end of line */
  425.     EscSeq('E');        /* clear screen */
  426.     SetIoBuf();
  427.     
  428. /*    Txoff(); */
  429.     Rsconf((int) BAUD_DEFAULT, flowctl, ucr, rsr, tsr, scr);  /* init set */
  430.     Vsync(); Vsync();
  431. /*    Txon();     */
  432.  
  433.     speed = BAUD_DEFAULT;
  434.     Baudrate = BAUD_RATE;
  435.     
  436.     aline_addr = aaddress();
  437.  
  438.     help();
  439.  
  440.     i = 0;
  441.     while (0 == 0)    /* infinite loop */
  442.     {
  443.         while (Bconstat(rs232) != 0)
  444.         {
  445.             /* Char at Modem */
  446.             c = Bconin(rs232) & 0x007f;
  447.             Bconout(console, c);
  448.  
  449.             /* Check the console once in a while */
  450.             /* important at High speeds */
  451.             if ((++i) & 32)
  452.             {
  453.                 if (Bconstat(console) != 0)
  454.                       {
  455.                     conin = Bconin(console);
  456.                     Bconout(rs232, (int) (conin & 0x007f));
  457.                 }
  458.                 i = 0;
  459.             }
  460.                 
  461.         }
  462.         
  463.         if (Bconstat(console) != 0)
  464.         {
  465.             /* Char at Console */
  466.             conin = Bconin(console);
  467.             if ((conin & 0x00FF0000L) == 0x00610000L)  /* Undo */
  468.             {
  469.                 ResetIoBuf();
  470.                 finish();
  471.             }
  472.             
  473.             if ((conin & 0x00FF0000L) == 0x00620000L)  /* Help */
  474.                 help();
  475.             else
  476.                 Bconout(rs232, (int) (conin & 0x007f));
  477.         }
  478.     }
  479. }
  480.  
  481. finish()
  482. {
  483. #ifdef MWC
  484.     free(bufr);
  485.     free(m_screen);
  486. #endif
  487.  
  488.     Pterm0();
  489. }
  490.  
  491. /** EOF **/
  492.